package com.example.danny.provincetest01;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }


    public void getPro(View view) {
        new Thread(){
            @Override
            public void run() {
                try {
                    String url = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";
                    String ns = "http://WebXml.com.cn";
                    String action = "getRegionProvince";
                    HttpTransportSE trans = new HttpTransportSE(url);
                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                    SoapObject body = new SoapObject(ns, action);

                    envelope.setOutputSoapObject(body);
                    envelope.dotNet = true;
                    trans.call(ns + "/" + action, envelope);
                    System.out.println(envelope.bodyIn.getClass().getName());
                    System.out.println(envelope.getResponse().getClass().getName());
                    SoapObject so = (SoapObject)envelope.getResponse();

                    for(int i=0; i<so.getPropertyCount(); i++) {
                        Log.i("Danny", so.getProperty(i) + "...");
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
}
